// pages/patrolLog/patrolLog.js
const app = getApp()
const util = require('../../utils/util.js')

const lbbService = require('../service/service.js')

Page({

  /**
   * 页面的初始数据
   */
  data: {
    reportId: '',
    pile: [
      { description: '替换控制盒', num: 4},
      { description: 'RFID不识别', num: 4}
    ]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    let that = this
    console.log(options)
    that.setData({
      reportId: options.reportId,
      scrollHeight:app.getScrollHeight(0),
      hospitalId:options.hospitalId
    })
    lbbService.getReportCount({ reportId: parseInt(that.data.reportId)},function(res){
      that.setData({
        reportDetail: res?res:null
      })
    })
    that.getAxios()
  },
  InspectionList:function(e){
    var that=this
    let equlist=e.currentTarget.dataset.equlist
      wx.navigateTo({
        url: '/pages/equInspection/equInspection',
        success: function(res) {
          // 通过eventChannel向被打开页面传送数据
          res.eventChannel.emit('acceptEquTypeBack', { data: equlist })
        }
      })
  
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },
  getAxios() {
    wx.showLoading({
      title: '加载中',
    })
    var that = this;
    lbbService.getInspectUploadPic({
      lbmId: that.data.hospitalId,
      pageNum: that.data.pageNum ?that.data.pageNum:'',
      pileId: that.data.pileId ? that.data.pileId : '',
      equId: that.data.equId ? that.data.equId : '',
      inspectId: that.data.reportId ? that.data.reportId : '',
    }, function (res) {
      let dataList_Pile = res.data.filter((item)=>{ return item.pileId !=0})
      let dataList_Equ = res.data.filter((item)=>{ return item.equId != 0})
      console.log(dataList_Pile,dataList_Equ,'我丢丢对')
      console.log(res,'我丢丢对')
      that.setData({
        dataList_Pile : dataList_Pile,
        dataList_Equ : dataList_Equ
      })
      console.log(res)
      wx.hideLoading()
    })
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },
  toEquipDetail: function(e) {
    console.log(e)
    let item = e.currentTarget.dataset.detail
    let detail = JSON.stringify(item)
    wx.navigateTo({
      url: '/pages/logEquipItem/logEquipItem?detail=' + detail,
    })
  },
  // toPileDetail: function(e) {
  //   console.log(e)
  //   let item = e.currentTarget.dataset.detail
  //   let detail = JSON.stringify(item)
  //   wx.navigateTo({
  //     url: '/pages/logPileItem/logPileItem?detail=' + detail,
  //   })
  // },
  toPileDetail: function(e){
    console.log("输出了e",e)
    let num = e.currentTarget.dataset.id
    num =  num + 1
    console.log("输出了num", num)
    let reportId = this.data.reportId
    let reportIdStr = JSON.stringify(reportId)
    console.log("输出了reportId", reportIdStr)
     wx.navigateTo({
       url: '/pages/logPileItem/logPileItem?id=' + num + "&reportId=" + reportId
     })
  },
  ToTakePhoto(){
    wx.navigateTo({
      url: '../SCM/takePhotoRecord/takePhotoRecord?hospitalId='+this.data.hospitalId+'&inspectId='+this.data.reportId,
    })
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})